<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>客户信息</title>
<%@ include file="../../header_inc.jsp"%>
<script type="text/javascript" src="${ctx}/js/other.js"></script>
<script type="text/javascript">
				function append() {
					var params = {
		    	                winId:'win_adds_sysCustomerss',
		    	                title:'添加客户信息',
		    	                width:400,
		    	                height:300,
		    	                showUrl:'${ctx}/manage/sysCustomer/add',
		    	                refresh_fun:function(){
		    	                	$('#dg').datagrid('uncheckAll');
		    	                    $('#dg').datagrid('reload');
		    	                }
		    	                
		    	        };
		    	        open_fun(params);
				}

				function edit() {
					 	var id=0;
		                var name=null;
		                var row = $('#dg').datagrid('getSelected');
		            	//var row = $('#dg').datagrid('getSelections');
		            	var len = $('#dg').datagrid('getSelections').length; 
		            	
		               	if(len>1){
		               		$.messager.alert("提示","只能选择一个进行更改!");
		               	}
		               	else if(len==1 && row)
		                {
		                    id = row.custId;
		                    name = row.userName;
		                    
		                        //winId,title,width,height,showUrl,okUrl,refresh_fun
		                        var params = {
		                                winId:'win_edit_syscustomer',
		                                title:'修改 '+name+' 的资料',
		                                width:350,
		                                height:300,
		                                showUrl:'/manage/sysCustomer/edit?id='+id,
		                                refresh_fun:function(){
		                                	$('#dg').datagrid('uncheckAll');
		                                    $('#dg').datagrid('reload');
		                                }
		                                
		                        };
		                        open_fun(params);   
		                    
		                }           
		                else
		                {
		                    $.messager.alert("提示","请选择要修改的信息!");
		                }
				}


				function deleteit() {
					var ids = [];
		        	var len = $('#dg').datagrid('getSelections').length; 
		        	var rows = $('#dg').datagrid('getSelections');
		        	for(var i=0; i<rows.length; i++){
		        		ids.push(rows[i].custId);
		        	}
		            if(!len)
		            {
		                $.messager.alert("提示","请选择要删除的数据！");
		            }
		            else
		            {	
		                $.messager.confirm("删除确认","是否要删除你选择的数据？",function(conf){
		                    if(conf)
		                    {	
		                        var url = "${ctx}/manage/sysCustomer/delete?custIds="+ids;
		                        $.getJSON(url, function(json){
		                            if(json.success==0)
		                            {
		                            	$('#dg').datagrid('uncheckAll');
		                                $('#dg').datagrid('reload');
		                            }
		                            else
		                            {
		                            	$.messager.alert("删除失败",json.msg);
		                            }
		                        });
		                    }                                       
		                });
		            }
				}
				//学校改变时自动搜索
				function searchIt() {
					$('#dg').datagrid('load',{
						depId: $('#sysDepartment_depId').val(),
						userName: $('#userName').val()
					});
				}
				function searchBeforeDelUserName(){
					$('#userName').val('');
					searchIt();
				}

				
				//右侧菜单
				function formatOper(val, row, index) {
					return '<a href="#" onclick="show_fun();"><input class="btn" type="button" value="资料" ></a>  <a href="#" onclick="editone();"><input class="btn" type="button" value="修改" ></a>  <a href="#" onclick="deleteone();"><input class="btn" type="button" value="删除" ></a>';
				}
				//右侧菜单
				function showStatus(status) {
					if(status==0){
						return "<font color='blue'>"+"正常"+"</font>";
					}
					return "<font color='red'>"+"禁用"+"</font>";
				}
				
				
				//格式化日期
				function formatDate (strTime) {
				    var date = new Date(strTime);
				    return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
				}
				
				 //以下三个函数为单个操作
		        function editone(){
		        	//alert(row);
		        	var row = $('#dg').datagrid('getSelected');
		        	var id = row.custId;
		        	var name = row.userName;
		            //winId,title,width,height,showUrl,okUrl,refresh_fun
		            var params = {
		                    winId:'win_edit_fjeduSchoolCard',
		                    title:'修改 '+name+' 的信息',
		                    width:350,
		                    height:300,
		                    showUrl:'${ctx}/manage/sysCustomer/edit?id='+id,
		                    refresh_fun:function(){
		                    	$('#dg').datagrid('uncheckAll');
		                        $('#dg').datagrid('reload');
		                    }
		                    
		            };
		            open_fun(params);   
		        	
		        }
		        function deleteone(){
		        	var row = $('#dg').datagrid('getSelected');
		        	var id = row.custId;
		        	var name = row.userName;
		        	 $.messager.confirm("删除确认",'删除&nbsp; <span style="color:red;font-weight:bold">'+id+'-'+name+'</span> &nbsp;？',function(conf){
		                 if(conf)
		                 {	
		                     var url = "${ctx}/manage/sysCustomer/delete?custIds="+id;
		                     $.getJSON(url, function(json){
		                         if(json.success==0)
		                         {
		                         	$('#dg').datagrid('uncheckAll');
		                             $('#dg').datagrid('reload');
		                         }
		                         else
		                         {
		                        	 $.messager.alert("删除失败",json.msg);
		                         }
		                        
		                     });
		                 }                                       
		             });
		    	
		        }
		        
		        
		        //显示用户详细
		    	function show_fun()
		    	{
		    			var row = $('#dg').datagrid('getSelected');
		        		var id = row.custId;
		        		var name = row.userName;
		    	       var params = {
		    	                winId:'win_showuser_sysCustomer',
		    	                title:name+'的详细资料',
		    	                width:700,
		    	                height:425,
		    	                showUrl:'${ctx}/manage/sysCustomer/queryCustDetail?id='+id,
		    	                refresh_fun:function(json){
		  
		     	                	$('#dg').datagrid('uncheckAll');
		      	                    $('#dg').datagrid('reload');

		    	                }
		    	                
		    	        };
		    	       ShowUserFun(params);

		    	}
				
			</script>
</head>
 <style type="text/css" media="screen">
 	.btn
	{
    	border-right: #63B8FF 1px solid;
   		padding-right: 2px;
    	border-top: #63B8FF 1px solid;
    	padding-left: 2px;
    	font-size: 12px;
    	FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=0,  StartColorStr=#ffffff,  EndColorStr=#C3DAF5);
    	border-left: #63B8FF 1px solid;
    	cursor: hand;
    	color: black;
    	padding-top: 2px;
    	border-bottom: #63B8FF 1px solid;

	}
 	
 </style>
<body class="easyui-layout">
	<div data-options="region:'north',border:false" style="height: 0px; background: #EEEEEE; padding: 5px">
		<form id="formModule" method="post">
		&nbsp;&nbsp;
            学校：<select id="sysDepartment_depId" name="sysDepartment" style="width: 120px;height: 22px;text-align:center"  onchange="searchBeforeDelUserName();">
                	<option value="0">全部</option>
                	<c:forEach var="sharedUser" items="${dep }">
      					<option value="${sharedUser.depId }">${sharedUser.depName}</option>
      				</c:forEach>
                </select>&nbsp;&nbsp;&nbsp;&nbsp;
                

    	姓名：<input id="userName"  maxlength="10" onchange="searchIt();" class="easyui-validatebox textbox" type="text"  name="userName" style="width:150px;height: 20px;" ></input>
		
                &nbsp;
                <a href="javascript:void(0)" class="easyui-linkbutton"
				data-options="iconCls:'icon-search',plain:true" onclick="searchit()">查询</a>           
    	</form>
	</div>
	<div data-options="region:'center',title:''">
		<div id="toolbar" style="height: auto">
			
			<a href="javascript:void(0)" class="easyui-linkbutton"
				data-options="iconCls:'icon-add',plain:true" onclick="append()">添加</a>
			<a href="javascript:void(0)" class="easyui-linkbutton"
				data-options="iconCls:'icon-remove',plain:true" onclick="edit()">修改</a>
			<a href="javascript:void(0)" class="easyui-linkbutton"
				data-options="iconCls:'icon-undo',plain:true" onclick="deleteit()">删除</a>
		</div>
		
		
				
		<table id="dg" class="easyui-datagrid" title="客户信息" fit="true"
			style="width: 700px; height: 250px"
			data-options="rownumbers:true,singleSelect:false,url:'/manage/sysCustomer/dataGrid',method:'get',toolbar:'#toolbar',fit:true,
				showFooter:true,pagination:true,idField:'custId'">
		
			<thead>
				<tr>
					<th data-options="field:'',width:60,checkbox:true">全选</th>
					<th data-options="field:'custId',width:30,align:'center'">编号</th>
					<th data-options="field:'userName',width:150,align:'center'">姓名</th>
					<th data-options="field:'sysDepartment',width:180,align:'center',formatter:showDept">学校</th>
					<th data-options="field:'phone',width:180,align:'center'">手机号码</th>
					<th data-options="field:'status',width:80,align:'center',formatter:showStatus">状态</th>
					<th data-options="field:'_operate',width:180,align:'center',formatter:formatOper">操作</th>
					
				</tr>
			</thead>
		</table>
	</div>
</body>
</html>